package math

// 计算 array 中的最小值
// 返回 最小值 和 最小值的下标

func MinInt(a []int) (int, int) {
	switch len(a) {
	case 0:
		return 0, 0
	case 1:
		return a[0], 0
	}

	var k = 0
	var v = a[0]

	for i := 1; i < len(a); i++ {
		if v > a[i] {
			k, v = i, a[i]
		}
	}

	return v, k
}

func MinInt64(a []int64) (int64, int) {
	switch len(a) {
	case 0:
		return 0, 0
	case 1:
		return a[0], 0
	}

	var k = 0
	var v = a[0]

	for i := 1; i < len(a); i++ {
		if v > a[i] {
			k, v = i, a[i]
		}
	}

	return v, k
}

func MinUInt(a []uint) (uint, int) {
	switch len(a) {
	case 0:
		return 0, 0
	case 1:
		return a[0], 0
	}

	var k = 0
	var v = a[0]

	for i := 1; i < len(a); i++ {
		if v > a[i] {
			k, v = i, a[i]
		}
	}

	return v, k
}

func MinUInt64(a []uint64) (uint64, int) {
	switch len(a) {
	case 0:
		return 0, 0
	case 1:
		return a[0], 0
	}

	var k = 0
	var v = a[0]

	for i := 1; i < len(a); i++ {
		if v > a[i] {
			k, v = i, a[i]
		}
	}

	return v, k
}

func MinFloat64(a []float64) (float64, int) {
	switch len(a) {
	case 0:
		return 0, 0
	case 1:
		return a[0], 0
	}

	var k = 0
	var v = a[0]

	for i := 1; i < len(a); i++ {
		if v > a[i] {
			k, v = i, a[i]
		}
	}

	return v, k
}
